package com.lin.controller;

import com.lin.annotation.MyLog;
import com.lin.services.LogServices;
import com.lin.utils.PageUnit;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * ClassName:LogController
 * Package:com.lin.controller
 * Author: hellcat
 * Date: 2019/12/20
 * ♣♣♣ 日志系统
 */

@Controller
@RequestMapping("/log")
public class LogController {
    @Autowired
    private LogServices logServices;

    @MyLog("查看日志")
    @RequiresPermissions("log:showLog")
    @RequestMapping("/toLog")
    public String toLog(HttpServletRequest request) {
        request.setAttribute("ddId", "Log");
        return "logMain";
    }

    @RequiresPermissions("log:showLog")
    @RequestMapping("/getLogInfo")
    @ResponseBody
    public Map<String, Object> getLogInfo(HttpServletRequest request) {
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");
        return PageUnit.Page(logServices.listLog(), Integer.parseInt(page), Integer.parseInt(limit));
    }
}
